#1、利用map批量检查用户名是否符合规范=>username符合规范，username不符合规范
#只能包括数字，字母，下划线，不能以数字开头，长度在6-18之间
# import re
# lst1=["tx","tx1234tsdghy","1asysuiv","uered28w","hsdh_236sdy"]
# def func1(username):
#     ret = re.findall(r"^[a-zA-Z_]\w{5,17}",username)
#     if ret==[]:
#         return username+"不合规范"
#     else:
#         return username+"符合规范"
# result = map(func1,lst1)
# print(list(result))

#2、filter把合法的用户名显示出来
import re
lst1=["tx","tx1234tsdghy","1asysuiv","uered28w","hsdh_236sdy"]
def func1(username):
    ret = re.findall(r"^[a-zA-Z_]\w{5,17}",username)
    if ret==[]:
        return False
    else:
        return True
result = filter(func1,lst1)
print(list(result))


# 3、匿名函数+reduce实现1*2*3*4...*n
# from functools import  reduce
# a=[]
# for i in range(1,100):
#    a.append(i)
# print(reduce(lambda x,y:x*y,a))

#4、filter函数:找到[1-100]能被3整除的数
# def func1(x):
#     return x%3 == 0
#
# a=[]
# for i in range(1,100):
#    a.append(i)
# result = filter(func1,a)
# print(list(result))

#5、map函数:求list[1-10]各项的平方
# def func1(item):
#     return item*item
#
# lst1 = [1,2,3,4,5,6,7,8,9,10]
# result = map(func1,lst1)
# print(list(result))
# 6、将列表[1,4,5,9]转换成’1459‘的字符
# from functools import  reduce
# def func2(x,y):
#     return str(x)+str(y)
#
# lst2 = [1,4,5,9]
# result = reduce(func2,lst2)
# print(result)
# print(type(result))
# print(reduce(lambda x,y:str(x)+str(y),lst2))


# import re
# username=[]
# while 1:
#     username.append(input("请输入用户名："))
#     if username=='q':
#         break
#     print(f"username={username}")
#     def username_check(username):
#         ret = re.findall(r"^[a-zA-z_][\w]{5,17}", username)
#         # 判断是否符合规范
#         if ret==[]:
#             return username+"不符合规范"
#         else:
#             return username+"符合规范"
#     result=map(username_check,username)
#     print(list(result))

lst3 = [7,-8,5,4,0,-2,-5]
#正数在前面负数在后
#正数从小到大
#负数从大到小
# print(sorted(lst3,reverse=True))
# print(sorted(lst3,key=lambda x:(x<0,abs(x))))

#字符串排序,排序规则(小写<大写<奇数<偶数)
#原理：先比较元组的第一个值，FALSE
s = 'asdf234GDSdsf23'
# print(sorted([True,False]))
print("".join(sorted(s,key=lambda x:(x.isdigit(),x.isdigit()and int(x) % 2==0,x.isupper(),x))))